#!/bin/bash
mvn dockerfile:build dockerfile:push -P uat

# git rev-parse --short HEAD
# git log -1  --format=%ci
# git rev-list --count HEAD
declare shortRev=$(git rev-parse --short HEAD)
declare timestamp=$(git log -1 --format=%ct)
declare formateddate=$(date +%Y%m%d-%H%M%S -d @$timestamp)

declare imagePrefix=$(echo '${docker.image.prefix}' | mvn help:evaluate -P uat | grep -v '^[[]')
declare imageTag=$(echo '${docker.image.tag}' | mvn help:evaluate -P uat | grep -v '^[[]')
declare artifactId=$(echo '${project.artifactId}' | mvn help:evaluate -P uat | grep -v '^[[]')



newTag=$imageTag-$formateddate-$shortRev
registry=$imagePrefix/$artifactId

echo $registry:$imageTag
echo $registry:$newTag

docker tag $registry:$imageTag $registry:$newTag
docker push $registry:$newTag